﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using Microsoft.AspNet.Identity.EntityFramework;
using TelerikedIn.Models;
using System.ComponentModel.DataAnnotations;

namespace TelerikedIn.WebApp.Areas.Administration.Models
{
    public class UserDetailsVM
    {
        public UserDetailsVM()
        {
            this.Image = new byte[1];
        }

        [ScaffoldColumn(false)]
        public string Id { get; set; }

        [Display(Name = "Username", Prompt = "Username")]
        [Required]
        public string UserName { get; set; }

        [Display(Name = "First name", Prompt = "First name")]
        [Required]
        public string FirstName { get; set; }

        [Display(Name = "Last name")]
        [Required]
        public string LastName { get; set; }

        public string City { get; set; }

        public string Country { get; set; }

        public string Education { get; set; }

        public byte[] Image { get; set; }

        [Display(Name = "Is banned")]
        public bool IsBanned { get; set; }

        [Display(Name = "Is admin")]
        public bool IsAdmin { get; set; }

        public static Expression<Func<ApplicationUser, UserDetailsVM>> FromUser
        {
            get
            {
                return u => new UserDetailsVM()
                {
                    Id = u.Id,
                    UserName = u.UserName,
                    FirstName = u.FirstName,
                    LastName = u.LastName,
                    City = u.City,
                    Country = u.Country,
                    Education = u.Education,
                    Image = u.Image,
                    IsBanned = u.Management.DisableSignIn,
                    IsAdmin = u.Roles.FirstOrDefault().Role.Name == "Administrator"
                };
            }
        }
    }
}